import deepmerge from "vendor/utils/T/core/deepmerge";

export interface EnumEnvType {
    rootPath?: string,                            // 根路由前缀
    staticPublicPath?: string,                    // 静态资源公共路径
    apiDomain?: string,        // api地址
    apiResponseCode?:{
        apiSuccessCode?: string,                    // 请求成功响应code
        errorCode?: string,                       // 请求失败响应code
        noLoginCode?: string,                       // 未登录的code
        noPermissionCode?: string,                       // 未登录的code
        invalidParamCode?: string,                  // 参数校验失败code
    },
    allowBrowser?:{
        name: string,
        minVersion: number
    }[],
    intl?: {
        lang?: string,                 // 语言
        timeZoneOffset?: number,     // 时区偏差, 单位分钟
    },
    app?: {
        title?: string,
        logo?: string,
    }
}

let EnumEnv: EnumEnvType = deepmerge<EnumEnvType>({
    rootPath: "/",                            // 根路由前缀
    staticPublicPath: "/public",              // 静态资源公共路径
    apiDomain: "",                            // api地址
    apiResponseCode:{
        apiSuccessCode: "200",                    // 请求成功响应code
        errorCode: "error",                       // 请求失败响应code
        noLoginCode: "401",                       // 未登录的code
        noPermissionCode: "403",                  // 没有权限的code
        invalidParamCode: "400",                  // 参数校验失败code
    },

    allowBrowser:[                            // 允许的浏览器类型和版本，如果不设置将不会检查
        {name: "chrome", minVersion: 0},
        {name: "mozilla", minVersion: 0},
        {name: "opera", minVersion: 0},
        {name: "safari", minVersion: 0},
        {name: "konqueror", minVersion: 0},
    ],
    intl: {
        lang: 'zh',                 // 语言
        timeZoneOffset: 8 * 60,     // 时区偏差, 单位分钟
    },
    app: {
        title: "Yaws-React",
        logo: require("../img/logo.png").default
    },
}, window.ENV);

export const getEnv = () => EnumEnv;

export const setEnv = (env: EnumEnvType) => {
    EnumEnv = deepmerge(EnumEnv, env || {});
};

